var test;
$(document).click(function () {
    layer.close(test)
    $('a').removeClass('shadow');
});
$(document).on('click','.btn-group',function (e) {
    e.stopPropagation();
});

$(document).on('click','.layui-layer',function (e) {
    e.stopPropagation();
});

/**
 * 点击再预约
 */
appointment = function (customerId,reservationsId,doctor) {
    layer.close(test)
    var cid = customerId + "," + reservationsId + "," + doctor;
    var index = layer.open({
        type: 2,
        title: '新建预约',
        area: ['60%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_appointment/' + cid
    });
    this.layerIndex = index;
};

/**
 * 发送短信
 */
shortMessage = function (customerId) {
    layer.close(test)
    var index = layer.open({
        type: 2,
        title: '发送消息',
        area: ['60%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/msgSend/to_msgSend/' + customerId
    });
    this.layerIndex = index;
};

/**
 * 点击进入患者详情
 */
openBilee = function (ide) {
    layer.close(test)
    var index = layer.open({
        type: 2,
        title: '到店客户详情',
        area: ['100%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/consultant/to_openBileLists/' + ide
    });
    this.layerIndex = index;
};

/**
 * 点击修改
 */
modifyAppointment = function(ids) {
    layer.close(test)
    var index = layer.open({
        type: 2,
        title: '修改预约客户',
        area: ['60%', '90%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/doctor_addTasks/' + ids
    });
    this.layerIndex = index;
};

/**
 * 点击取消预约
 */
cancelAppointment = function(customerId,customerName,calEvent) {
    if(confirm("确定患者【"+customerName+"】要取消预约?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/cancelAppointment",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                layer.close(test)
                Feng.success('取消预约成功!');
                $('#calendar').fullCalendar('updateEvent', calEvent);
                parent.layer.close(parent.layer.getFrameIndex(window.name))
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击挂号
 */
registerAppointment = function (customerId,customerName,calEvent) {
    if(confirm("确定患者【"+customerName+"】已挂号?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/regresses",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                layer.close(test)
                Feng.success('患者' + customerName + '挂号成功!');
                calEvent.arrivalStatus = "2";
                calEvent.backgroundColor = "#4058a1";
                calEvent.borderColor = "#4058a1";
                $('#calendar').fullCalendar('updateEvent', calEvent);
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击取消确定   预约
 */
noSureAppointment = function (customerId,customerName,calEvent) {
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/no_sureAppointment",
        type: "post",
        data: {
            customerId: customerId
        },
        success: function (data) {
            layer.close(test)
            calEvent.arrivalStatus = "1";
            calEvent.backgroundColor = "#4099ff";
            calEvent.borderColor = "#4099ff";
            $('#calendar').fullCalendar('updateEvent', calEvent);
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
};
/**
 * 点击确定
 */
sureAppointment = function (customerId,customerName,calEvent) {
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/sureAppointment",
        type: "post",
        data: {
            customerId: customerId
        },
        success: function (data) {
            layer.close(test)
            calEvent.arrivalStatus = "6";
            calEvent.backgroundColor = "#017cdc";
            calEvent.borderColor = "#017cdc";
            $('#calendar').fullCalendar('updateEvent', calEvent);
        },
        error: function (data) {
            alert('内部故障!');
        }
    });
};
/**
 * 点击开始治疗
 */
startTreatment = function (customerId,customerName,calEvent) {
    if(confirm("确定患者【"+customerName+"】已经开始治疗?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/startTreatment",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                layer.close(test)
                Feng.success('患者' + customerName + '开始治疗!');
                calEvent.arrivalStatus = "3";
                calEvent.backgroundColor = "#ffba40";
                calEvent.borderColor = "#ffba40";
                $('#calendar').fullCalendar('updateEvent', calEvent);
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击完成治疗
 */
completionTreatment = function (customerId,customerName,calEvent) {
    if(confirm("确定患者【"+customerName+"】已经完成治疗?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/completionTreatment",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                layer.close(test)
                Feng.success('患者' + customerName + '完成治疗!');
                calEvent.arrivalStatus = "4";
                calEvent.backgroundColor = "#2dc87e";
                calEvent.borderColor = "#2dc87e";
                $('#calendar').fullCalendar('updateEvent', calEvent);
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击离开
 */
alreadyLeave = function (customerId,customerName,calEvent) {
    if(confirm("确定患者【"+customerName+"】已经离开?")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/alreadyLeave",
            type: "post",
            data: {
                customerId: customerId
            },
            success: function (data) {
                layer.close(test)
                Feng.success('患者' + customerName + '已经离开!');
                calEvent.arrivalStatus = "5";
                calEvent.backgroundColor = "#61b740";
                calEvent.borderColor = "#61b740";
                $('#calendar').fullCalendar('updateEvent', calEvent);
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击回退
 */
fallbackAction = function (customerId,customerName,arrivalStatus,calEvent) {
    if(confirm("确定要回退么？ 患者【"+customerName+"】")) {
        $.ajax({
            url: Feng.ctxPath + "/doctorLooked/fallbackAction",
            type: "post",
            data: {
                customerId: customerId,
                arrivalStatus:arrivalStatus
            },
            success: function (data) {
                layer.close(test)
                Feng.success('患者' + customerName + '回退成功!');
                if(calEvent.arrivalStatus == "2"){
                    calEvent.arrivalStatus = "1";
                    calEvent.backgroundColor = "#4099ff";
                    calEvent.borderColor = "#4099ff";
                }else if(calEvent.arrivalStatus == "3"){
                    calEvent.arrivalStatus = "2";
                    calEvent.backgroundColor = "#10428b";
                    calEvent.borderColor = "#10428b";
                }else if(calEvent.arrivalStatus == "4"){
                    calEvent.arrivalStatus = "3";
                    calEvent.backgroundColor = "#ffba40";
                    calEvent.borderColor = "#ffba40";
                }else if(calEvent.arrivalStatus == "5"){
                    calEvent.arrivalStatus = "4";
                    calEvent.backgroundColor = "#2dc87e";
                    calEvent.borderColor = "#2dc87e";
                }
                $('#calendar').fullCalendar('updateEvent', calEvent);
            },
            error: function (data) {
                alert('内部故障!');
            }
        });
    }
};
/**
 * 点击打印
 */
printingAppointment = function (customerId) {
    layer.close(test)
    var index = layer.open({
        type: 2,
        title: '打印客户信息',
        area: ['60%', '100%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/printingAppointment/' + customerId
    });
    this.layerIndex = index;
};

/**
 * 点击刷新
 */
btnRefetchEvents = function () {
    $('#calendar').fullCalendar( 'refetchEvents' );
};
/**
 * 修改黄页编号
 */
numberedModification = function (customerId,yellowNumber) {
    var yi = customerId + "," + yellowNumber;
    var index = layer.open({
        type: 2,
        title: '修改黄页编号',
        area: ['30%', '40%'], //宽高
        fix: true, //不固定
        maxmin: true,
        content: Feng.ctxPath + '/doctorLooked/numberedModification/' + yi
    });
    this.layerIndex = index;
};

